﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Application.App;
using AutoMapper;
using Domain.Model;
using DTO;
using FacadeApi.Extension;
using Infrastructure.Error;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.IO;

namespace FacadeApi.Controllers
{

    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class UserFirendsController : ControllerBase
    {
        public UserFirendsApplication userFirendsApplication { get; set; }
        public ILogger<UserFirendsController> _logger { get; set; }
      
        /// <summary>
        /// 获取好友信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetFirendsInfo()
        {
            try
            {
                var uid = User.Claims.First(i => i.Type == "ID").Value;
                var r = userFirendsApplication.GetFirendsInfo(int.Parse(uid));

                return this.Success(r);
            }
            catch (BizException ex)
            {
                return this.FailResult(ex.data, ex.Message);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
                return this.FailResult(null, "系统繁忙，请稍后重试!");
            }

        }
        /// <summary>
        /// 获取好友列表
        /// </summary>
        /// <param name="level">1,2</param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetFirendsList(int level,int page,int size)
        {
            try
            {
                var uid = User.Claims.First(i => i.Type == "ID").Value;
                var r = userFirendsApplication.GetFirendsList(int.Parse(uid), level,page,size);

                return this.Success(r);
            }
            catch (BizException ex)
            {
                return this.FailResult(ex.data, ex.Message);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
                return this.FailResult(null, "系统繁忙，请稍后重试!");
            }

        }
    }
}
